package main

import (
	"fmt"
)

func getSub(s string) (string, int) {
	c := map[uint8]int{}
	for i := 0; i < len(s); i++ {
		if _, b := c[s[i]]; b {
			return s[:i], c[s[i]]
		} else {
			c[s[i]] = i + 1
		}
	}
	return s, len(s)
}

func getSub2(s string) (string, int) {
	c := [26]int{0}
	fmt.Println(c)
	for i := 0; i < len(s); i++ {
		fmt.Println(s[i] - 97)
		if c[s[i]-97] != 0 {
			return s[:i], c[s[i]-97]
		} else {
			c[s[i]-97] = i + 1
		}
	}
	return s, len(s)
}

func lengthOfLongestSubstring(s string) int {
	maxSubstring := ""
	for i := 0; i < len(s); {
		//fmt.Println(maxSubstring,i)
		sub, j := getSub(s[i:])
		if len(sub) > len(maxSubstring) {
			maxSubstring = sub
		}
		i += j
	}
	fmt.Println(maxSubstring)
	return len(maxSubstring)
}

func main() {
	s := "abcabcbbz "
	s = "anviaj"
	s = " "
	a := lengthOfLongestSubstring(s)
	fmt.Println(a, s)
	getSub2("z")
	fmt.Println(string("a")[0])
}
